﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class NativeAOT
{
    [UnmanagedCallersOnly(EntryPoint = "funpqv")]
    public static unsafe double funpqv(IntPtr x_ptr, IntPtr b_ptr, int n, double t)
    {
        double* x = (double*)x_ptr.ToPointer();
        double* b = (double*)b_ptr.ToPointer();

        return funpqv(x, b, n, t);
    }

    /// <summary>
    /// 计算函数连分式值
    /// </summary>
    /// <param name="x">存放n个结点值x[0]～x[n-1]。</param>
    /// <param name="b">存放连分式中的n+1个参数b[0]～b[n]</param>
    /// <param name="n">连分式的节数（注意：常数项b[0]为第0节）</param>
    /// <param name="t">自变量值</param>
    /// <returns>函数返回t处的函数连分式值</returns>
    public static unsafe double funpqv(double* x, double* b, int n, double t)
    {
        int k;
        double u;
        u = b[n];
        for (k = n - 1; k >= 0; k--)
        {
            if (Math.Abs(u) + 1.0 == 1.0)
            {
                u = 1.0e+35 * (t - x[k]) / Math.Abs(t - x[k]);
            }
            else
            {
                u = b[k] + (t - x[k]) / u;
            }
        }
        return (u);
    }

}

